const { defineConfig } = require('@vue/cli-service')
const path = require('path')

function resolve(dir) {
  return path.join(__dirname, dir)
}
module.exports = defineConfig({
  transpileDependencies: true,
  productionSourceMap:false, // 取消map文件
  publicPath:"/", // 输入
  outputDir:"dist",// 输出
  assetsDir: 'static',//输出的静态资源目录名 没有默认放到根目录下  static
  devServer: {
    port: 8080,
    open: false,
    // host: "localhost",
    // hot: true,
    proxy: {
      '/api': {
        target: 'http://192.168.1.159:20020', // 服务器端接口地址
        ws: false, // 如果要代理 websockets，配置这个参数
        // 如果是https接口，需要配置这个参数
        changeOrigin: true, // 是否跨域
        pathRewrite: {
          '^/api': '/'
        }
      },
    }
  },
  configureWebpack: {
    // provide the app's title in webpack's name field, so that
    // it can be accessed in index.html to inject the correct title.
    // name: '智能',
    resolve: {
      alias: {
        '@': resolve('src')
      }
    }
  },
  chainWebpack: (config) => {
    let title = ''
    if (process.env.NODE_ENV === 'production') { 
      title = 'production'   // 为生产环境修改配置...
    } else { 
      title = 'development'   // 为开发环境修改配置...
    }
    config
    .plugin('html')
      .tap(args => {
        args[0].title = title;
        return args
    })
    config.optimization.splitChunks({
      chunks: 'all',
      cacheGroups: {
        vendors: {
          name: 'chunk-vendors',
          test: /[\\/]node_modules[\\/]/,
          priority: 10,
          chunks: 'initial' // only package third parties that are initially dependent
        },
        vantUI: {
          name: 'chunk-vantUI', // split elementUI into a single package
          priority: 20, // the weight needs to be larger than libs and app or it will be packaged into libs or app
          test: /[\\/]node_modules[\\/]_?vant(.*)/ // in order to adapt to cnpm
        },
        commons: {
          name: 'chunk-commons',
          test: resolve('src/commons'), // can customize your rules
          minChunks: 3, //  minimum common number
          priority: 5,
          reuseExistingChunk: true
        }
      }
    })
  },
})
